/*
 * Copyright 2012-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.sql.init.dependency;

import java.util.Set;

import javax.sql.DataSource;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;

/**
 * 用于检测初始化 SQL 数据库的 Bean。实现类应在
 * {@code META-INF/spring.factories} 中以键
 * {@code org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector}
 * 注册。
 *
 * @author Andy Wilkinson
 * @since 2.5.0
 */
public interface DatabaseInitializerDetector extends Ordered {

	/**
	 * 检测在给定的 {@code beanFactory} 中定义的、用于初始化
	 * {@link DataSource} 的 Bean。
	 * @param beanFactory 要检查的 Bean 工厂
	 * @return 检测到的 {@code DataSource} 初始化器 Bean 名称集合，
	 *         如果没有检测到则返回空集合。
	 */
	Set<String> detect(ConfigurableListableBeanFactory beanFactory);

	/**
	 * 回调方法，表示所有已知的 {@code DataSourceInitializerDetector} 均已调用，
	 * 并完成对初始化 {@link DataSource} 的 Bean 的检测。
	 * @param beanFactory 被检查的 Bean 工厂
	 * @param dataSourceInitializerNames 所有已知检测器检测到的
	 *                                    {@code DataSource} 初始化器 Bean 名称集合
	 */
	default void detectionComplete(ConfigurableListableBeanFactory beanFactory,
			Set<String> dataSourceInitializerNames) {
	}

	@Override
	default int getOrder() {
		return 0;
	}

}
